In IDL versions 6.3 and later, you can create applications that allow users to drag tree nodes from a tree widget to a draw widget. Drag and drop functionality is not enabled by default. When creating an IDL application that incorporates both a tree widget and a draw widget you can enable drag and drop behavior to drag values from the tree widget to the draw widget. This section discusses the steps necessary to implement drag and drop functionality in your application.
Implementing drag and drop functionality in your application entails three steps:
When the user drags a group of selected nodes over a draw widget, IDL automatically calls the routine defined as the drag notification callback for the draw widget. The purpose of the drag notification callback is to provide the widget system with information about where dragged nodes can be dropped, allowing it to change the cursor display to indicate to the user whether nodes can be dropped at the current position. You, as an IDL application programmer, cannot respond to the value returned by the drag notification callback directly, but you can choose to specify your own version of the callback function to override the default behavior. Drag notification callbacks are specified via the DRAG_NOTIFY keyword to WIDGET_DRAW, or the SET_DRAG_NOTIFY keyword to WIDGET_CONTROL.
Drag notifications are also generated when the state of a drag modifier key changes (either up or down). If you override the default drag notification callback, you can use this information to update the drag cursor with a plus symbol (+).
If no callback is defined for the draw widget, the default callback will be used.
The drag notification callback function returns an integer value calculated by performing an OR operation on the following values:
Value |
Meaning |
0 |
User cannot drop |
1 |
User can drop above |
2 |
User can drop onto |
4 | User can drop below |
8 | Show the plus indicator |
For example, if the callback returns the value 3, the use can drop onto the draw widget and the plus indicator will be displayed.
The default drag notification callback function is used if no function is specified for the draw widget. The default callback returns 0 if drop events are not enabled (DROP_EVENTS=0) and 1 otherwise.
In most cases, the default drag notification callback should be adequate for an application that allows the user to drop tree nodes onto a draw widget. If it proves inadequate, however, you can create a custom callback to perform extra processing.
The drag notification callback routine has the following signature:
FUNCTION Callback_Function_Name, Destination, Source, $
X, Y, Modifiers, Default
where
Modifiers indicates the state of the modifier keys. The widget system generates them by ORing the following values together for the depressed keys:
Bitmask |
Modifier Key |
1 |
Shift |
2 |
Control |
4 |
Caps Lock |
8 |
Alt |
Note: For UNIX, the Alt key is the currently mapped MOD1 key.
The return value should indicate where a drop is allowed to take place relative to the destination widget and whether the “+” symbol should appear with the drag cursor, as described in the table above under "Drag Notification Callback Return Values." For additional information on writing drag notification callbacks, see Dragging and Dropping Tree Nodes.
When the user releases the mouse button over a valid drop target (that is, when the DROP_EVENTS keyword to WIDGET_DRAW has been set), a WIDGET_DROP event is generated. Your application’s event handler should recognize this drop event and perform some action.
The drop event’s information is contained in a WIDGET_DROP structure. (See DROP_EVENTS in the reference section for WIDGET_DRAW for a full definition of the WIDGET_DROP structure.) The important components of the structure when responding to drop events are:
The IDL distribution contains an example that contains a tree widget representing various image files and a draw widget onto which the tree nodes can be dragged to display the images.
Example Code: The draw widget drag and drop example is included in the file drag_and_drop_draw.proin the examples/doc/widgets subdirectory of the IDL distribution. Run this example procedure by entering drag_and_drop_draw at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT drag_and_drop_draw.pro.